package com.qiyu.tech.gateway.event;

import com.qiyu.tech.gateway.auth.IBlackListCache;
import com.qiyu.tech.gateway.auth.IBlackListCacheManager;
import com.qiyu.tech.gateway.dao.mapper.BlackListMapper;
import com.qiyu.tech.gateway.dao.po.BlackListPO;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.Serializable;

/**
 * @Author linhao
 * @Date created in 12:04 下午 2021/3/19
 */
@Component
public class InsertNodeListener implements ApplicationListener<InsertNodeEvent> {

    @Resource
    private IBlackListCache iBlackListCache;

    @Resource
    private BlackListMapper blackListMapper;

    @Override
    public void onApplicationEvent(InsertNodeEvent event) {
        BlackListPO blackListPO = blackListMapper.selectById(event.getBlackListPOId());
        if (blackListPO != null) {
            Long insertNodeId = (Long) event.getSource();
            iBlackListCache.setInCacheMap(blackListPO.getIdentification(),blackListPO);
            System.out.println("接收到数据id is " + insertNodeId);
        }
    }
}
